<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            width:1000px;
            height: 1000px;
            border: 1px solid black;
            position: relative;
        }
        div {
            width: 200px;
            height: 200px;
            background-color:black;
            font-size: 100px;
            color: blanchedalmond;
            text-align: center;
            /* 文字水平居中 */
            line-height: 200px;
            /* 文字高度垂直居中 */
        }
        .box1 {
            /* 使用绝对定位方式 */
            position:absolute;
            left: 50%;
            transform: translate(-50%);

        }
        .box2 {
            /* 使用margin方式 */
            margin: 300px auto;
            font-size: 100px;
        }
    </style>
</head>
<body>
    <div class="box1">1</div>
    <div class="box2">2</div>
</body>
</html>